<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎加入U享书库</title>
    <link rel="shortcut icon" href="/static/bg_img/favicon.ico">
    <link rel="stylesheet" href="{{ url_for('static', filename='layui/css/layui.css') }}">
    <script type="text/javascript"
            src="{{ url_for('static', filename='jquery/jquery-3.6.0.js') }}"></script>
    <script type="text/javascript">
        function loginForAjax() {
            uname = $("#uname_login").val();
            if (uname.length == 0) {
                layer.msg("username can`t null", {icon: 2})
                return
            }
            upwd = $("#upwd_login").val();
            if (upwd.length == 0) {
                layer.msg("PassWord can`t null", {icon: 2})
                return
            }
            if (upwd.length < 4) {
                layer.msg("PassWord can`t lt 4", {icon: 2})
                return
            }
            $.ajax({
                url: '/login',
                data: $("#f_login").serialize(),
                method: "post",
                success: function (result) {
                    if (result["stats"] == 10) {
                        layer.msg("login sucess", {
                            time: 1500,
                            icon: 1
                        }, function () {
                            window.location.href = '/index?username=' + result["name"]
                        })
                    } else if (result["stats"] == 11) {
                        layer.msg("login sucess, 欢迎您管理员！", {
                            time: 1500,
                            icon: 1
                        }, function () {
                            window.location.href = '/manager'
                        })
                    } else if (result["stats"] == 2) {
                        layer.msg("账户不存在，请注册！", {
                            time: 3000,
                            icon: 2
                        }, function () {
                        });
                    } else
                        layer.msg("login fault, 请检查密码是否正确！", {
                            time: 3000,
                            icon: 2
                        }, function () {
                        });
                },
                error: function (e) {
                    {#window.location.href = '/admin'#}
                    layer.msg("请求服务器失败！！", {
                        icon: 1,
                        time: 3000
                    })
                }
            })
        }


        function registerForAjax() {
            uname = $("#uname_register").val();
            upwd = $("#upwd_register").val();
            cupwd = $("#cupwd_register").val();
            nickname = $("#nickname").val()
            if (uname.length == 0) {
                layer.msg("username can`t null", {icon: 2})
                return
            }
            if (upwd.length == 0) {
                layer.msg("PassWord can`t null", {icon: 2})
                return
            }
            if (cupwd.length == 0) {
                layer.msg("Cu-PassWord can`t null", {icon: 2})
                return
            }
            if (upwd.length < 6) {
                layer.msg("PassWord can`t lt 6", {icon: 2})
                return
            }
            if (upwd != cupwd) {
                layer.msg("User-Pwd != Cu-Pwd", {icon: 2})
                return
            }
            $.ajax({
                url: "register",
                method: "post",
                data: $("#f_register").serialize(),
                success: function (result) {
                    if (result == '1') {
                        layer.msg("register sucess", {
                            time: 1500,
                            icon: 1
                        }, function () {
                            window.location.href = '/loginANDregister'
                        })
                    } else if (result == "2") {
                        alert("该邮箱已被注册!");
                    } else {
                        alert("Fault!")
                    }
                },
                error: function (e) {
                    alert("conn error!")
                }
            });
        }
    </script>

</head>
<body style="background: url(/static/bg_img/bg_LR.jpg) no-repeat">
<center>
    <br><br><br>
    <br><br>
    <div style="width: 40%">
        <div class="layui-card">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">登陆</li>
                    <li>注册</li>
                </ul>

                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <fieldset class="layui-elem-field">
                            <legend>登陆页面</legend>
                        </fieldset>
                        <form action="#" method="post" id="f_login" name="f_login" class="layui-form">
                            <div class="layui-form-item">
                                <label class="layui-form-label">Email:</label>
                                <div class="layui-input-block">
                                    <input id="uname_login" name="uname_login" class="layui-input" placeholder="请输入邮箱">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码:</label>
                                <div class="layui-input-block">
                                    <input type="password" id="upwd_login" name="upwd_login" class="layui-input"
                                           placeholder="请输入密码">
                                </div>
                            </div>
                            <div class="layui-form-item" align="center">
                                <a href="javascript:loginForAjax()" class="layui-btn"><span
                                        class="layui-icon layui-icon-user"></span>登陆</a>
                                <a href="javascript:f_login.reset()" class="layui-btn layui-btn-warm"><span
                                        class="layui-icon layui-icon-fonts-clear"></span>重置</a>
                            </div>
                        </form>
                    </div>


                    <div class="layui-tab-item">
                        <fieldset class="layui-elem-field">
                            <legend>注册页面</legend>
                        </fieldset>
                        <form action="#" method="post" id="f_register" name="f-register" class="layui-form">
                            <div class="layui-form-item" align="center">
                                <label class="layui-form-label">Email:</label>
                                <div class="layui-input-block">
                                    <input type="text" id="uname_register" name="uname_register" class="layui-input"
                                           placeholder="请输入注册邮箱">
                                </div>
                            </div>

                            <div class="layui-form-item" align="center">
                                <label class="layui-form-label">用户名:</label>
                                <div class="layui-input-block">
                                    <input type="text" id="nickname" name="nickname" class="layui-input"
                                           placeholder="请输入你的昵称">
                                </div>
                            </div>

                            <div class="layui-form-item" align="center">
                                <label class="layui-form-label">密码:</label>
                                <div class="layui-input-block">
                                    <input type="password" id="upwd_register" name="upwd_register" class="layui-input"
                                           placeholder="请输入注册密码">
                                </div>
                            </div>
                            <div class="layui-form-item" align="center">
                                <label class="layui-form-label">确认密码:</label>
                                <div class="layui-input-block">
                                    <input type="password" id="cupwd_register" name="cupwd_register" class="layui-input"
                                           placeholder="请输入确认密码">
                                </div>
                            </div>
                            <div class="layui-form-item" align="center">
                                <a href="javascript:registerForAjax()" class="layui-btn"><span
                                        class="layui-icon layui-icon-user"></span>注册</a>
                                <a href="javascript:f_register.reset()" class="layui-btn layui-btn-warm"><span
                                        class="layui-icon layui-icon-fonts-clear"></span>重置</a>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="{{ url_for('static', filename='layui/layui.js') }}"></script>
</center>
</body>
<br><br><br>
<center>
    <footer class="text-center">
    <p>Copyright &#169; 2021-2022 飞鹰团队, Lales.</p>
    </footer>
</center>
</html>